#include <iostream>
using namespace std;

#include <vector>
#include <algorithm>


int bitsum(int n)
{
    int sum = 0, tmp;
    while (n > 0)
    {
        tmp = n % 10;
        sum += (tmp * tmp);
        n /= 10;
    }

    return sum;
}


bool isHappy(int n) {
    int slow = n, fast = bitsum(n);
    while (slow != fast)
    {
        slow = bitsum(slow);
        fast = bitsum(bitsum(fast));
    }

    return slow == 1;
}

int main()
{
    int flag = 0;
    for (int i = 1; i < INT_MAX; i++)
    {
        if (flag % 220 == 0 && flag != 0)
        {
            flag = 0;
            cout << endl;
        }

        if (isHappy(i))
        {
            cout << i << " ";
            ++flag;
        }
    }

    return 0;
}